package com.sit.jike.hrproject.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sit.jike.hrproject.bean.SearchBean;
import com.sit.jike.hrproject.entity.HrDept;
import com.sit.jike.hrproject.service.IHrDeptService;
import com.sit.jike.hrproject.util.CommonTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Allen
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/hrDept")
public class HrDeptController {
    @Autowired
    private IHrDeptService hrDeptService;

    @Autowired
    private CommonTool commonTool;

    @GetMapping("/hello")
    public Map<String, Object> sayHello() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("姓名", "22计科");
        map.put("班级", "1班");
        map.put("say", hrDeptService.hello());
        map.put("fromTool", commonTool.getSomething());
        return map;
    }

    @GetMapping("/list1")
    public Map<String, Object> list1(String deptName) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list1", hrDeptService.getAll(deptName));
        return map;
    }

    @GetMapping("/list2")
    public Map<String, Object> list2(String deptName) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list2", hrDeptService.getAllMap(deptName));
        return map;
    }

    @GetMapping("/list3page")
    public Map<String, Object> list3page(SearchBean bean) {
        IPage<Map<String, Object>> page = hrDeptService.getAllMapWithPage(bean);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", page.getTotal());
        map.put("data", page.getRecords());
        return map;
    }

    @PostMapping("/deleteDept")
    public Map<String, Object> deleteDept(String id) {
        String res = hrDeptService.deleteDept(id);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", res);

        return map;
    }

    @PostMapping("/saveDeptInfo")
    public Map<String, Object> saveDeptInfo(@RequestBody HrDept hrDept) {
        hrDeptService.saveDeptInfo(hrDept);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", "ok");

        return map;
    }
}
